Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan 2.x #408

Draft
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Draft

phpstan 2.x #408

wants to merge 4 commits into from

Conversation

rudiedirkx
Copy link

Phpstan is very useful for finding flaws, even at level 2. Larastan makes it work for Laravel projects. Your IDE might be less happy, if it doesn't have great Laravel support like Larastan provides for Phpstan. I don't have a 'smart' IDE at all, so it works like a charm for me. Several dubious findings:

  • Where do Server/ServerResource properties auto_update and security_updates come from? According to Server they're database columns, but I can't find them. Not even in old migrations/git history.
  • The SSH helper doesn't know if it's an SSH or SFTP connection, because it's created before it's connected, and the connect($sftp) call decides which it's gonna be. A generic on the SSH class could help, but that feels odd. Feels like it should be 2 classes.

@saeedvaziry
Copy link
Member

Thanks for the effort. The docblocks in the Model classes are very useful for auto-completion. why did you remove them?

@saeedvaziry
Copy link
Member

Besides, I would start with phpstan itself instead of larastan and with level 1

@saeedvaziry
Copy link
Member

Just did a quick check on my local wth phpstan itself. found 9 errors on level 1 and 256 errors on level 2. shouldn't be difficult to fix them.

@rudiedirkx
Copy link
Author

rudiedirkx commented Dec 24, 2024

The docblocks in the Model classes are very useful for auto-completion. why did you remove them?

Because some of them were wrong (array instead of Collection, eg.

vito/app/Models/Site.php

Lines 293 to 296 in dfdd50b

public function hasSSL(): bool
{
return $this->ssls->isNotEmpty();
}
), and Larastan makes those better automatically. But if your IDE doesn't understand Laravel like Larastan does, this is a big miss, I get that.

I would start with phpstan itself instead of larastan and with level 1

Phpstan without Larastan doesn't work, because Larastan is what makes sense of the loads of 'magic' in Laravel. There's also a level 0, but level 0 and 1 and 2 are all simple enough.

@rudiedirkx
Copy link
Author

found 9 errors on level 1 and 256 errors on level 2. shouldn't be difficult to fix them.

Many of those 256 might be easy, and some of them will be impossible, because of Laravel's PHP magic. Larastan 'fixes' that with its Phpstan extensions. You also need fewer inline @var then.

@saeedvaziry
Copy link
Member

Phpstan without Larastan doesn't work, because Larastan is what makes sense of the loads of 'magic' in Laravel. There's also a level 0, but level 0 and 1 and 2 are all simple enough.

I think its just configuration, it has worked on Laravel itself. should be easy to make it work on Vito as well.

@rudiedirkx
Copy link
Author

rudiedirkx commented Dec 25, 2024

You can copy Larastan functionality, but why would you? That's why Larastan exists. It sounds like you're against Larastan specifically. Why? I like it. It covers all the Laravel magic, you can code like you're used to. You can even keep all the class @property, but they do have to be correct (Collection instead of array etc). Larastan won't overwrite manual @property tags. Downside of manual property tags is that they might be nonsense, and you won't know. For instance what's up with auto_update and security_updates in Server? Are those columns? Do they exist? They're in $fillable too, but not in any migration. Do they still exist, or is it just the @property tag that still exists?

Anyway, you're the boss, you decide if and how you want static analysis. I think it already found a few issues even at level 2.

@rudiedirkx
Copy link
Author

When the 2 mixed options are enabled, I expect many more errors, many of which aren't real errors, but Phpstan won't understand the code, because of Laravel magic handled by Larastan.

@rudiedirkx
Copy link
Author

When the 2 mixed options are enabled, I expect many more errors, many of which aren't real errors, but Phpstan won't understand the code, because of Laravel magic handled by Larastan.

Many of those are Filament errors, but Filament doesn't provide Phpstan extensions, so you'd need to better type, and/or make custom extensions. I think. I don't know Filament at all.

@saeedvaziry
Copy link
Member

Lets keep this open for a bit. Need to think more. Still have a bit of doubts of adding phpstan or not 🤔

@rudiedirkx
Copy link
Author

Still have a bit of doubts of adding phpstan or not 🤔

It is a hassle getting it to work, but when it does it's nice to have an extra layer of protection.

@saeedvaziry
Copy link
Member

saeedvaziry commented Dec 25, 2024

I totally agree with the need for such tool as the bigger the project goes and more contributors come in, we need more protection. I need to figure out what setup is the best for Vito.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants